import {
  config
} from "../common/config"
import { upload } from "../config/api"

/**
 * 判断是否需要添加前缀
 * @param {String} 图片链接
 * @return {String} 
 */
export const prefixURL = (Url) => {
  if (!Url) return
  return Url = Url.indexOf('http') == -1 ? `${config.staticURL}${Url}` : Url

}
/**
 * 上传文件
 * @param {String} 临时路径
 * @param {Object} 携带参数
 * @return {String}
 */
export const _upload = (url, formData = {}) => {
  return new Promise((resolve, reject) => {
    uni.uploadFile({
      url: `${config.uploadURL}${upload}`, // 仅为示例，非真实的接口地址
      filePath: url,
      name: 'file',
      formData,
      header: {
        token: '4285bcda-dd68-42d2-ab26-81bf84ccaf03'
      },
      success: (res) => {
        resolve(JSON.parse(res.data).data.url);
      },
    });
  });
  upload(row)
}
export const setCache = (name, data) => {
  try {
    uni.setStorageSync(name, data);
  } catch (e) {
    console.log(e)
  }
}

export const getCache = (name) => {
  let data;
  try {
    data = uni.getStorageSync(name);
  } catch (e) {
    console.log(e);
  }
  return data;
}